<template>
  <div class="page">
    <Navbar title="中介排行" />
    <van-tabs v-model="activeTab" color="#4B93FE" @change="onRefresh">
      <van-tab title="红榜" :name="1" />
      <van-tab title="黑榜" :name="2" />
    </van-tabs>
    <div class="content">
      <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
        <van-empty v-if="!tableData.length" description="暂无数据" />
        <div class="list">
          <div
            v-for="(item,index) in tableData"
            :key="index"
            class="list-item"
          >
            <div v-if="item.icon" class="list-item-header f-r a-c">
              <img :src="item.icon" alt="">
              <span class="title">{{ item.corporateName }}</span>
            </div>
            <div v-else class="list-item-header f-r a-c">
              <span class="title"><span v-if="activeTab == 1">{{ index + 1 }}、</span>{{ item.corporateName }}</span>
            </div>
            <div class="score f-r a-c">
              综合评分：
              <van-rate
                v-model="item.score"
                allow-half
                :size="12"
                color="#EA9518"
                void-icon="star"
                void-color="#eee"
              />
              <span class="score-value" style="color: #EA9518;">{{ item.score }}</span>
            </div>
            <div class="list-item-footer f-r a-c j-b">
              <div class="count">
                办件评价量：<span style="color: #2F86FD">{{ item.sum }}</span>件
              </div>
              <div class="tobtn" style="color: #2F86FD;" @click="toDetail(item, index + 1)" >
                查看中介详情 >
              </div>
            </div>
          </div>
        </div>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import refresh from '@/mixins/refresh'
import { http_mediation } from '@/api'
import { Toast } from 'vant'
export default {
  name: 'Project',
  mixins: [refresh],
  data() {
    return {
      filterIcon: require('@/assets/home/filter.png'),
      tableData: [
      ],
      activeTab: 1,
      statusName: {
        0: '未关联 ',
        1: '未评价（已办理成功）  ',
        2: '已评价  ',
        3: '已关联未办理 '
      }
    }
  },
  methods: {
    routerJump(item) {
      if (this.activeTab === 2) return
      this.$router.push({
        path: '/evaluation-create',
        query: {
          projectId: item.projectId,
          id: item.id,
          intermediaryId: item.intermediaryId,
          eventId: item.eventId,
          eventName: item.eventName,
          corporateName: item.corporateName
        }
      })
    },
    toDetail(item, index) {
      this.$router.push({
        path: '/mediation-detail',
        query: {
          userId: item.userId,
          id: item.id,
          index: index
        }
      })
    },
    onRefresh() {
      this.pageNo = 1
      this.getList()
    },
    getList() {
      // 操作
      if (this.pageNo > 1 && this.tableData.length >= this.totalSize) return Toast('没有更多了')
      if (this.activeTab === 1) {
        http_mediation.pagered().then(res => {
          if (this.pageNo === 1) {
            this.tableData = res.data.records.map((el, index) => {
              return {
                icon: index < 3 ? require(`@/assets/home/top${index + 1}.png`) : '',
                ...el
              }
            })
          } else {
            this.tableData = [
              ...this.tableData,
              ...res.data.records.map(el => {
                return {
                  ...el
                }
              })
            ]
          }
          this.totalSize = res.data.length
          this.refreshLoading = false
        })
      } else {
        // 问题
        http_mediation.pageblack({
          ...this.getQueryParams()
        }).then(res => {
          if (this.pageNo === 1) {
            this.tableData = res.data.records.map(el => {
              return {
                ...el
              }
            })
          } else {
            this.tableData = [
              ...this.tableData,
              ...res.data.records.map(el => {
                return {
                  ...el
                }
              })
            ]
          }
          this.totalSize = res.data.total
          this.refreshLoading = false
        })
      }
    }
  }
}
</script>

  <style scoped lang="scss">

  .page {
      .search-header {
          background-color: #fff;
          padding: 10px 0;
          padding-right: 0.32rem;
          .filter-box {
              flex-shrink: 0;
              font-size: 12px;
              font-family: PingFang SC;
              font-weight: 500;
              color: #333333;
          }
      }
      .list {
        .list-item {
            padding: 12px 20px;
            background-color: #fff;
            border-radius: 10px;
            margin-bottom: 20px;
            .list-item-footer {
                .count {
                    font-size: 12px;
                    line-height: 12px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #666666;
                }
                .tobtn {
                    font-size: 12px;
                    line-height: 12px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #2F86FD;
                }
            }
            .list-item-header {
                margin-bottom: 10px;
                img {
                   width: 18px;
                    height: 20px;
                    margin-right: 7px;
                }
                .title {
                    font-size: 16px;
                    line-height: 16px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #333333;
                }
            }

            .score {
                font-size: 12px;
                line-height: 12px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #666666;
                margin-bottom: 13px;
            }
        }
    }
  }
  </style>
